//
//  JXTabBarViewController.m
//  EducationManagementSystem
//
//  Created by 大鼻子露珠 on 2017/1/6.
//  Copyright © 2017年 大鼻子露珠. All rights reserved.
//

#import "JXTabBarViewController.h"
#import "ClassroomViewController.h"
#import "LeaveViewController.h"
#import "TimeViewController.h"
#import "NoticeViewController.h"
#import "MeViewController.h"



@interface JXTabBarViewController ()

@property(nonatomic, strong) NSMutableArray<UIViewController *> *childVCs;

@end

@implementation JXTabBarViewController

-(instancetype)init{
    self = [super init];
    if (self) {
        self.tabBar.tintColor = [UIColor blueColor];
        self.tabBar.backgroundColor = [UIColor whiteColor];
        self.tabBar.barTintColor = [UIColor whiteColor];
        //是否tabbar不透明
        self.tabBar.opaque = YES;
        //是否tabbar半透明
        self.tabBar.translucent = NO;
        
        //初始化一个数组去保存控制器
        self.childVCs = [NSMutableArray array];
        //创建子视图的方法
        [self addChildVCs];
    }
    return self;
}


-(void)addChildVCs{
    [self addChildViewControllerWithTitle:@"班级" withControllerName:@"ClassroomViewController" withVcNormalImage:@"class" withVcSelectedImage:@"class02"];
    [self addChildViewControllerWithTitle:@"批假" withControllerName:@"LeaveViewController" withVcNormalImage:@"approve" withVcSelectedImage:@"approve02"];
    [self addChildViewControllerWithTitle:@"考勤" withControllerName:@"TimeViewController" withVcNormalImage:@"work-attendance" withVcSelectedImage:@"work-attendance02"];
    [self addChildViewControllerWithTitle:@"通知" withControllerName:@"NoticeViewController" withVcNormalImage:@"Mail" withVcSelectedImage:@"Mail02"];
    [self addChildViewControllerWithTitle:@"我" withControllerName:@"MeViewController" withVcNormalImage:@"user" withVcSelectedImage:@"user02"];
    
}

# pragma -- 创建子视图的封装方法
//title 名字
//controllerName控制器名字(控制器要继承自公用的控制器)//继承只是为了使用基础视图的label
//vcNormalImage
//vcSelectedImage
//
-(void)addChildViewControllerWithTitle:(NSString *)title withControllerName:(NSString *)controllerName withVcNormalImage:(NSString *)vcNormalImage withVcSelectedImage:(NSString *)vcSelectedImage{
    
    UIViewController *vc = [[NSClassFromString(controllerName) alloc] init];
    vc.tabBarItem = [[UITabBarItem alloc]initWithTitle:title image:[UIImage imageNamed:vcNormalImage] selectedImage:[UIImage imageNamed:vcSelectedImage]];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    vc.title = title;
//    ???
    [self.childVCs addObject:nav];
//    ???
    self.viewControllers = self.childVCs;
    
}



@end
